<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算属性和方法</title>
</head>
<body>
    <!-- 
        参考学习： https://cn.vuejs.org/guide/essentials/computed.html
    -->
    <script src="./vue.global.prod.js"></script>

    <div id="app">
        <span>{{ calculateBooksMessage() }}</span>
        <span>{{ calculateBooksMessage() }}</span>
        <span>{{ calculateBooksMessage() }}</span>
        <br>
        <span>{{ booksMessage }}</span>
        <span>{{ booksMessage }}</span>
        <span>{{ booksMessage }}</span>

    </div>

    <script>
        // 对象解构，从Vue对象中获取createApp函数
        const { createApp } = Vue

        // 通过createApp函数创建一个app对象
        const app = createApp({
            data() {
                return {
                    author: {
                        name: 'John Doe',
                        books: [
                            'Vue 2 - Advanced Guide',
                            'Vue 3 - Basic Guide',
                            'Vue 4 - The Mystery'
                        ]
                    }
                }
            },
            methods: {
                calculateBooksMessage() {
                    console.log('methods: calculateBooksMessage()');
                    return this.author.books.length > 0 ? 'Yes' : 'No'
                }
            },
            computed: {
                booksMessage() {
                    console.log('computed: booksMessage()');
                    return this.author.books.length > 0 ? 'Yes' : 'No'
                }
            }
        })

        // app对象挂载到id="app"的HTML元素，关联起来
        app.mount('#app')

    </script>

</body>
</html>